package com.colabo.j2ee.web.core.log;

import java.net.URL;

import org.apache.log4j.xml.DOMConfigurator;

/**
 * A programmatically init the log4j implementation. Used in the init process of the application<br>
 * <b>RECOMMAND:</b> config the log4j implementation in the <code>web.xml</code> file, not use this;<br>
 * &lt;context-param&gt; <br>
 * &nbsp;&nbsp;&lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;<br>
 * &nbsp;&nbsp;&lt;param-value&gt;classpath:/conf/env/log4j.xml&lt;/param-value&gt;<br>
 * &lt;/context-param&gt;<br>
 * ....... <br>
 * &lt;listener&gt;<br>
 * &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;<br>
 * &lt;/listener&gt;<br>
 * @author Anthony Do
 * @since 2009-12-23
 *
 */
public class LogManager {
	private static boolean ISINITED = false;

	public static synchronized void init(String logConfigFilePath) {
		if (ISINITED) {
			return;
		}
		System.setProperty("com.colabo.commons.logging.LogFactory", "com.colabo.commons.logging.impl.LogFactoryImpl");
		System.setProperty("com.colabo.commons.logging.Log", "com.colabo.commons.logging.impl.Log4JLogger");
		URL path = LogManager.class.getResource(logConfigFilePath);
		System.setProperty("log4j.configuration", path.getFile());

		DOMConfigurator.configure(path.getFile());

		ISINITED = true;
	}
}
